﻿Imports extranet.BE
Imports extranet.BC
Imports MetodosComuns

Partial Class forum_adm_editar_topico
    Inherits System.Web.UI.Page
    Dim strID As String
    Dim objBETopico As BETopico

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objBESeguranca As New BESeguranca
        Dim objBEUsuario As BEUsuario = Session("objBEUsuario")

        If IsNothing(objBEUsuario) Then Response.Redirect(TELA_LOGOUT)
        Session("strTela") = MetodosComuns.GetCurrentPageName()
        If Not IsPostBack Then          ' SEGURANÇA
            objBESeguranca = BCSeguranca.SelecionaPermissoes(objBEUsuario.GrupoAcesso, Session("strTela"))
            If Not objBESeguranca.Autorizado Then Response.Redirect(TELA_LOGOUT)
            Session("objBESeguranca") = objBESeguranca
        Else
            objBESeguranca = Session("objBESeguranca")
        End If

        If objBESeguranca.Escrita Then 'Verificar aki se usuário tem permissao de administrador
            If Not IsPostBack Then
                objBETopico = New BETopico
                strID = Request.QueryString("id")
                objBETopico = BCForum.SelecionaTopico(strID)

                txtNome.Text = objBETopico.Titulo
                If objBETopico.Visivel Then
                    DropDownList1.SelectedIndex = 1
                Else
                    DropDownList1.SelectedIndex = 0
                End If
            End If
        Else
            Response.Redirect(TELA_LOGOUT)
        End If
    End Sub

    Protected Sub btnCancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Dim objBETopico As New BETopico
        strID = Request.QueryString("id")
        objBETopico = BCForum.SelecionaTopico(Convert.ToInt32(strID))
        Response.Redirect("subcategoria.aspx?id=" & objBETopico.IdSubcategoria)
    End Sub

    Protected Sub btnGravar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGravar.Click
        objBETopico = New BETopico

        strID = Request.QueryString("id")
        objBETopico.Id = strID
        objBETopico.Titulo = txtNome.Text
        If DropDownList1.SelectedIndex = 1 Then
            objBETopico.Visivel = True
        Else
            objBETopico.Visivel = False
        End If

        BCForum.AlteraTopico(objBETopico)

        objBETopico = BCForum.SelecionaTopico(Convert.ToInt32(strID))
        Response.Redirect("subcategoria.aspx?id=" & objBETopico.IdSubcategoria)
    End Sub
End Class
